package com.ys.timer;

import com.ys.entity.hr.ThrOperateCompanyApply;
import com.ys.service.business.TpShopRegisterPhaseRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import java.util.*;


@Controller
public class TimerTPShopRegisterPhaseRecordDaily {
	private static final Logger logger = LoggerFactory.getLogger(TimerTPShopRegisterPhaseRecordDaily.class);

	@Autowired
	private TpShopRegisterPhaseRecordService tpShopRegisterPhaseRecordService;


	//获取当天新增的的数据
	@Scheduled(cron = "0 */5 * * * ?")//间隔5分钟执行一次
	//@Scheduled(cron = "0 */1 * * * ?")
	//@Scheduled(cron = "5 * * * * * ")
	public void addhopRegisterPhaseRecordDailyByCompany() {
		try {
			//logger.info("*************开始定时新增运营公司备案跟踪记录*************");
			List<ThrOperateCompanyApply> applyList = new ThrOperateCompanyApply()
					.where("( SELECT COUNT ( 1 ) AS num FROM TP_ShopRegisterPhaseRecord B WHERE B.OperateCompanyId = A.id ) = 0 ")
					//.where("A.EffectStock=1")
					.where("A.UpdateTime > DATEADD(day, 0, getdate())")
					.queryList();

			if(applyList!=null && applyList.size()>0){
				for(int i=0;i<applyList.size();i++){
					Map<String, Object> msg = new HashMap();
					msg.put("operateCompanyId",applyList.get(i).getId());
					msg.put("phaseNum",1);
					//新增
					tpShopRegisterPhaseRecordService.add(msg);
				}
			}
			//logger.info("*************完成定时新增运营公司备案跟踪记录*************");
		}catch (Exception e){
			//e.printStackTrace();
			logger.error("定时新增运营公司备案跟踪记录出错：",e.getMessage(),e);
		}

	}




}
